package com.example.hrsystem.data.source;

import androidx.room.Dao;
import androidx.room.Delete;
import androidx.room.Insert;
import androidx.room.Query;
import androidx.room.Update;

import com.example.hrsystem.workflow.model.OvertimeRequest;

import java.util.Date;
import java.util.List;

/**
 * 加班申请数据库访问接口
 * 提供对加班申请的数据库操作
 */
@Dao
public interface OvertimeRequestDao {
    /**
     * 获取所有加班申请
     */
    @Query("SELECT * FROM overtime_requests")
    List<OvertimeRequest> getAllOvertimeRequests();

    /**
     * 根据ID获取加班申请
     */
    @Query("SELECT * FROM overtime_requests WHERE id = :id")
    OvertimeRequest getOvertimeRequestById(int id);

    /**
     * 根据流程实例ID获取加班申请
     */
    @Query("SELECT * FROM overtime_requests WHERE processInstanceId = :processInstanceId")
    OvertimeRequest getOvertimeRequestByProcessInstanceId(int processInstanceId);

    /**
     * 根据申请人ID获取加班申请列表
     */
    @Query("SELECT * FROM overtime_requests WHERE applicantId = :applicantId")
    List<OvertimeRequest> getOvertimeRequestsByApplicantId(int applicantId);

    /**
     * 根据状态获取加班申请列表
     */
    @Query("SELECT * FROM overtime_requests WHERE status = :status")
    List<OvertimeRequest> getOvertimeRequestsByStatus(String status);

    /**
     * 根据加班类型获取加班申请列表
     */
    @Query("SELECT * FROM overtime_requests WHERE overtimeType = :overtimeType")
    List<OvertimeRequest> getOvertimeRequestsByType(String overtimeType);

    /**
     * 根据审批人ID获取待审批的加班申请列表
     */
    @Query("SELECT * FROM overtime_requests WHERE approverId = :approverId AND status = 'PENDING'")
    List<OvertimeRequest> getPendingOvertimeRequestsByApproverId(int approverId);

    /**
     * 查询指定日期范围内的加班申请
     */
    @Query("SELECT * FROM overtime_requests WHERE overtimeDate BETWEEN :startDate AND :endDate")
    List<OvertimeRequest> getOvertimeRequestsInDateRange(Date startDate, Date endDate);

    /**
     * 插入加班申请
     */
    @Insert
    void insert(OvertimeRequest request);

    /**
     * 更新加班申请
     */
    @Update
    void update(OvertimeRequest request);

    /**
     * 删除加班申请
     */
    @Delete
    void delete(OvertimeRequest request);
}